package com.qys.livesMall.shop.controller.sys;

import com.qys.livesMall.common.result.R;
import com.qys.livesMall.shop.modal.dto.shop.income.EditHierarchyIncomeConfig;
import com.qys.livesMall.shop.modal.vo.ShopIncomeConfigVO;
import com.qys.livesMall.shop.service.ShopIncomeConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * web-店铺收益分佣配置
 *
 * @author wzy
 * @since 2023-06-27
 */
@RestController
@RequestMapping("/sys/shopIncomeConfig")
public class ShopIncomeConfigController {

    @Autowired
    private ShopIncomeConfigService shopIncomeConfigService;

    /**
     * 获取店铺收益分配配置
     * @return
     */
    @GetMapping("/get")
    public R<ShopIncomeConfigVO> getConfig(){
        return shopIncomeConfigService.getConfig();
    }

    /**
     * 设置平台抽成
     * @param platform
     * @return
     */
    @PostMapping("/edit/platform")
    public R platform(@RequestBody Map<String,BigDecimal> platform){
        return shopIncomeConfigService.platform(platform.get("platform"));
    }

    /**
     * 设置主播抽成
     * @param anchor
     * @return
     */
    @PostMapping("/edit/anchor")
    public R anchor(@RequestBody Map<String,BigDecimal> anchor){
        return shopIncomeConfigService.anchor(anchor.get("anchor"));
    }

    /**
     * 设置商品先折扣
     * @param advancePayment
     * @return
     */
    @PostMapping("/edit/advancePayment")
    public R advancePayment(@RequestBody Map<String,BigDecimal> advancePayment){
        return shopIncomeConfigService.advancePayment(advancePayment.get("advancePayment"));
    }

    /**
     * 修改有效店铺余额
     * @param advancePayment
     * @return
     */
    @PostMapping("/edit/effectiveShop")
    public R effectiveShop(@RequestBody Map<String,BigDecimal> advancePayment){
        return shopIncomeConfigService.effectiveShop(advancePayment.get("effectiveShop"));
    }

    /**
     * 增加层级抽成
     * @param config
     * @return
     */
    @PostMapping("/add/hierarchy")
    public R addHierarchy(@RequestBody EditHierarchyIncomeConfig config){
        return shopIncomeConfigService.addHierarchy(config);
    }

    /**
     * 编辑层级抽成
     * @param config
     * @return
     */
    @PostMapping("/edit/hierarchy")
    public R editHierarchy(@RequestBody EditHierarchyIncomeConfig config){
        return shopIncomeConfigService.editHierarchy(config);
    }

    /**
     * 删除层级抽成
     * @param id
     * @return
     */
    @PostMapping("/del/{id}")
    public R editHierarchy(@PathVariable Integer id){
        return shopIncomeConfigService.delHierarchy(id);
    }
}
